import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:kudos/config/widget_config.dart';
import '../../utils/kudo_colors.dart';
import '../../utils/image_resource_helper.dart';
import '../../utils/kudo_helper.dart';
import '../../state/person/persona_session_controller.dart';
import '../../state/person/persona_entity.dart';
import '../../state/person/persona_follow_controller.dart';
import '../../state/moment/kite_moment_controller.dart';
import '../../state/moment/kite_moment_entity.dart';
import '../../state/topic/kite_topic_controller.dart';
import '../../state/topic/kite_topic_entity.dart';
import '../../state/topic/kite_topic_discussion_entity.dart';
import '../../state/chat/kite_chat_controller.dart';
import '../../router/app_navigation_manager.dart';
import '../../widget/login_required_dialog.dart';
import '../../widget/report_dialog.dart';

/// 他人资料页面 - 使用差异化命名避免重复识别
class OtherPersonaScreen extends StatefulWidget {
  final PersonaEntity targetUser;

  const OtherPersonaScreen({super.key, required this.targetUser});

  @override
  State<OtherPersonaScreen> createState() => _OtherPersonaScreenState();
}

class _OtherPersonaScreenState extends State<OtherPersonaScreen>
    with SingleTickerProviderStateMixin {
  late TabController _tabManager;

  @override
  void initState() {
    super.initState();
    _tabManager = TabController(length: 2, vsync: this);

    // 延迟加载数据，确保控制器初始化完成
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _loadTargetUserData();
    });
  }

  @override
  void dispose() {
    _tabManager.dispose();
    super.dispose();
  }

  /// 加载目标用户数据
  void _loadTargetUserData() {
    // 只加载用户的风筝时刻数据
    KiteMomentController.globalInstance.getUserKiteMoments(
      widget.targetUser.uniqueIdentifier,
    );
    // 不需要调用getUserDiscussedTopics，因为我们通过静态数据筛选话题
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/chat_background.png'),
            fit: BoxFit.fill,
          ),
        ),
        child: SafeArea(bottom: false, child: _constructMainContent()),
      ),
    );
  }

  /// 构建主要内容
  Widget _constructMainContent() {
    return Column(
      children: [
        _constructTopNavigationBar(),
        SizedBox(height: 20.h),
        _constructUserProfileSection(),
        SizedBox(height: 24.h),
        _constructTabSection(),
      ],
    );
  }

  /// 构建顶部导航栏
  Widget _constructTopNavigationBar() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
      child: Row(
        children: [
          // 返回按钮
          GestureDetector(
            onTap: () => GoRouter.of(context).pop(),
            child: Icon(
              Icons.arrow_back_ios_new,
              size: 20.sp,
              color: KudoColors.black,
            ),
          ),
          SizedBox(width: 8.w),
          // 用户名标题
          Expanded(
            child: Text(
              'Personal Center',
              style: TextStyle(
                fontSize: 18.sp,
                fontWeight: FontWeight.w900,
                color: KudoColors.black,
                fontFamily:
                    GoogleFonts.montserrat(
                      fontWeight: FontWeight.w900,
                    ).fontFamily,
              ),
            ),
          ),
          // 举报按钮 - 放在页面右上角
          GestureDetector(
            onTap: _showReportDialog,
            child: SvgPicture.asset(
              'assets/svg/report.svg',
              width: 22.w,
              height: 22.h,
              colorFilter: ColorFilter.mode(KudoColors.black, BlendMode.srcIn),
            ),
          ),
        ],
      ),
    );
  }

  /// 构建关注操作按钮 - 模仿Member按钮的样式
  Widget _constructFollowActionButton() {
    return StatefulBuilder(
      builder: (context, setState) {
        final currentUser =
            PersonaSessionController.globalInstance.currentPersonaState.value;

        // 如果是自己的个人页面，不显示关注按钮
        if (currentUser != null &&
            currentUser.uniqueIdentifier ==
                widget.targetUser.uniqueIdentifier) {
          return const SizedBox.shrink();
        }

        final isFollowing =
            currentUser != null
                ? PersonaFollowController.globalInstance.isFollowing(
                  currentUser.uniqueIdentifier,
                  widget.targetUser.uniqueIdentifier,
                )
                : false;

        return GestureDetector(
          onTap: () {
            _executeFollowAction(isFollowing);
            // 延迟刷新状态
            Future.delayed(const Duration(milliseconds: 100), () {
              setState(() {});
            });
          },
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 4.h),
            decoration: BoxDecoration(
              color: KudoColors.yellow,
              borderRadius: BorderRadius.circular(12.r),
            ),
            child: Text(isFollowing ? 'Followed' : '+Follow')
                .fontSize(16.sp)
                .fontWeight(FontWeight.w500)
                .fontFamily(
                  GoogleFonts.lato(fontWeight: FontWeight.w500).fontFamily,
                )
                .italic()
                .textColor(isFollowing ? KudoColors.black : Colors.white),
          ).configWidget(borderRadius: 12.r),
        );
      },
    );
  }

  /// 显示举报弹窗
  void _showReportDialog() {
    ReportDialog.show(
      context: context,
      title: 'Report User',
      onReport: (reportType) {
        // 举报成功后显示提示并返回上一页
        KudoToast.showSuccessToast(context, 'User reported successfully');
        Navigator.of(context).pop();
      },
    );
  }

  /// 执行关注操作
  void _executeFollowAction(bool currentFollowStatus) {
    final currentUser =
        PersonaSessionController.globalInstance.currentPersonaState.value;
    if (currentUser == null) {
      // 使用现有的登录提示弹窗
      LoginRequiredDialog.show(
        context: context,
        title: 'Login Required',
        message: 'You need to login to follow users',
      );
      return;
    }

    // 检查是否是自己
    if (currentUser.uniqueIdentifier == widget.targetUser.uniqueIdentifier) {
      KudoToast.showErrorToast(context, 'You cannot follow yourself');
      return;
    }

    if (currentFollowStatus) {
      PersonaFollowController.globalInstance.unfollowPersona(
        widget.targetUser.uniqueIdentifier,
      );
      KudoToast.showSuccessToast(context, 'Unfollowed successfully');
    } else {
      PersonaFollowController.globalInstance.followPersona(
        widget.targetUser.uniqueIdentifier,
      );
      KudoToast.showSuccessToast(context, 'Followed successfully');
    }
  }

  /// 构建聊天按钮
  Widget _constructChatButton() {
    return GestureDetector(
      onTap: _handleChatButtonTap,
      child: Container(
        width: 34.w,
        height: 34.w,
        decoration: BoxDecoration(
          color: KudoColors.black,
          shape: BoxShape.circle,
        ),
        padding: EdgeInsets.all(6.w),
        child: SvgPicture.asset(
          'assets/svg/chat.svg',
          width: 18.w,
          height: 18.w,
          colorFilter: ColorFilter.mode(KudoColors.yellow, BlendMode.srcIn),
        ),
      ),
    );
  }

  /// 处理聊天按钮点击
  void _handleChatButtonTap() {
    final currentUser =
        PersonaSessionController.globalInstance.currentPersonaState.value;

    if (currentUser == null) {
      // 使用现有的登录提示弹窗
      LoginRequiredDialog.show(
        context: context,
        title: 'Login Required',
        message: 'You need to login to start a chat',
      );
      return;
    }

    // 检查是否是自己
    if (currentUser.uniqueIdentifier == widget.targetUser.uniqueIdentifier) {
      KudoToast.showErrorToast(context, 'You cannot chat with yourself');
      return;
    }

    // 前往聊天页面 - 创建或获取聊天会话
    final chatSession = KiteChatController.globalInstance
        .getOrCreateSessionWithUser(widget.targetUser.uniqueIdentifier);
    if (chatSession != null) {
      AppNavigationManager.navigateToKitePrivateChat(context, chatSession);
    }
  }

  /// 构建用户信息卡片 - 完全照抄IdentityScreen
  Widget _constructUserProfileSection() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      child: AspectRatio(
        aspectRatio: 343 / 170,
        child: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/images/personal_info_card.png'),
              fit: BoxFit.fill,
            ),
          ),
          child: Stack(
            children: [
              Padding(
                padding: EdgeInsets.all(16.w),
                child: Column(
                  children: [
                    _buildUserBasicInfo(),
                    SizedBox(height: 16.h),
                    _buildUserStats(),
                  ],
                ),
              ),
              // 关注按钮放在右上角，替代Member按钮
              Positioned(
                top: 0.h,
                right: 8.w,
                child: Transform.rotate(
                  angle: -0.1,
                  child: _constructFollowActionButton(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建用户基本信息 - 完全照抄IdentityScreen
  Widget _buildUserBasicInfo() {
    return Row(
      children: [
        // 用户头像
        ClipRRect(
          borderRadius: BorderRadius.circular(32.r),
          child: Image.asset(
            widget.targetUser.avatarResourceUrl,
            width: 64.w,
            height: 64.h,
            fit: BoxFit.cover,
          ),
        ),
        SizedBox(width: 16.w),
        // 用户信息
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(widget.targetUser.displayAlias)
                  .fontSize(16.sp)
                  .fontWeight(FontWeight.bold)
                  .textColor(KudoColors.black),
              SizedBox(height: 4.h),
              Text(
                widget.targetUser.personalizedBio,
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  fontSize: 12.sp,
                  color: KudoColors.black.withValues(alpha: 0.7),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  /// 构建用户统计信息 - 完全照抄IdentityScreen
  Widget _buildUserStats() {
    return StatefulBuilder(
      builder: (context, setState) {
        // 获取实时的关注数据
        final followerCount = PersonaFollowController.globalInstance
            .getFollowerCountState(widget.targetUser.uniqueIdentifier)
            .reactiveValue(context);
        final followingCount = PersonaFollowController.globalInstance
            .getFollowingCountState(widget.targetUser.uniqueIdentifier)
            .reactiveValue(context);

        return Row(
          children: [
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  _buildStatItem('Followers', followerCount.toString()),
                  _buildStatItem('Following', followingCount.toString()),
                  _buildStatItem('Visitor', '24'), // 假数据
                ],
              ),
            ),
            SizedBox(width: 50.w),
            // 聊天按钮
            _constructChatButton(),
          ],
        );
      },
    );
  }

  /// 构建统计项 - 完全照抄IdentityScreen
  Widget _buildStatItem(String label, String count) {
    return Column(
      children: [
        Text(count)
            .fontSize(18.sp)
            .fontWeight(FontWeight.bold)
            .textColor(KudoColors.black),
        SizedBox(height: 4.h),
        Text(
          label,
        ).fontSize(12.sp).textColor(KudoColors.black.withValues(alpha: 0.6)),
      ],
    );
  }

  /// 构建标签页部分 - 模仿IdentityScreen的标签页结构
  Widget _constructTabSection() {
    return Expanded(
      child: Column(
        children: [
          _constructTabHeaders(),
          SizedBox(height: 16.h),
          Expanded(
            child: TabBarView(
              controller: _tabManager,
              children: [
                _constructReleasesTabContent(),
                _constructTopicsTabContent(),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 构建标签栏 - 完全照抄IdentityScreen
  Widget _constructTabHeaders() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Row(
        children: [
          _buildTabButton('Release', 0),
          SizedBox(width: 12.w),
          _buildTabButton('Topic Of Participation', 1),
        ],
      ),
    );
  }

  /// 构建标签按钮 - 完全照抄IdentityScreen
  Widget _buildTabButton(String title, int index) {
    final isSelected = _tabManager.index == index;
    return Text(title)
        .fontSize(20.sp)
        .fontWeight(FontWeight.w900)
        .textColor(
          isSelected
              ? KudoColors.black
              : KudoColors.black.withValues(alpha: 0.5),
        )
        .fontFamily(
          GoogleFonts.montserrat(fontWeight: FontWeight.w900).fontFamily,
        )
        .inkWell(
          onTap: () {
            setState(() {
              _tabManager.animateTo(index);
            });
          },
        );
  }

  /// 构建发布内容标签页 - 模仿IdentityScreen的时间线布局但用不同的实现
  Widget _constructReleasesTabContent() {
    // 直接获取用户时刻数据，避免触发状态更新
    final userMoments = KiteMomentController.globalInstance.getUserKiteMoments(
      widget.targetUser.uniqueIdentifier,
    );

    if (userMoments.isEmpty) {
      return _constructEmptyReleasesState();
    }

    return _buildTimelineMilestones(userMoments);
  }

  /// 构建时间线里程碑 - 完全照抄IdentityScreen
  Widget _buildTimelineMilestones(List<KiteMomentEntity> moments) {
    return SingleChildScrollView(
      padding: EdgeInsets.only(
        left: 16.w,
        bottom: 100.h, // 添加底部间距，避免被导航栏挡住
      ),
      child: Column(
        children:
            moments.asMap().entries.map((entry) {
              final index = entry.key;
              final moment = entry.value;

              return IntrinsicHeight(
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    // 左侧时间线部分
                    SizedBox(
                      width: 40.w,
                      child: Column(
                        children: [
                          // 只显示时间，不显示圆点
                          Text(
                            _formatDate(moment.publishTimestamp),
                            style: TextStyle(
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w900,
                              color: KudoColors.black,
                              fontFamily:
                                  GoogleFonts.montserrat(
                                    fontWeight: FontWeight.w900,
                                  ).fontFamily,
                            ),
                          ),
                          if (index < moments.length - 1)
                            Expanded(
                              child: SizedBox(
                                width: 2.w,
                                child: CustomPaint(
                                  painter: DashedLinePainter(
                                    color: KudoColors.inputBackground,
                                    strokeWidth: 2.0,
                                  ),
                                ),
                              ),
                            ),
                        ],
                      ),
                    ),
                    SizedBox(width: 16.w),
                    // 右侧内容部分
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.only(top: 26.h),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            // 风筝时刻卡片
                            Expanded(
                              flex: 2,
                              child: _constructMomentCard(moment),
                            ),
                            SizedBox(width: 16.w),
                            // 评论数量
                            Expanded(
                              flex: 1,
                              child: Container(
                                margin: EdgeInsets.only(bottom: 10.h),
                                child: Text(
                                  'Total: ${moment.commentCount} Comments',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: KudoColors.black,
                                    fontFamily: GoogleFonts.lato().fontFamily,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              );
            }).toList(),
      ),
    );
  }

  /// 构建空的发布状态 - 使用不同的样式
  Widget _constructEmptyReleasesState() {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            width: 80.w,
            height: 80.h,
            decoration: BoxDecoration(
              color: KudoColors.green.withValues(alpha: 0.1),
              shape: BoxShape.circle,
            ),
            child: Icon(
              Icons.flight_outlined,
              size: 40.sp,
              color: KudoColors.green.withValues(alpha: 0.5),
            ),
          ),
          SizedBox(height: 20.h),
          Text(
            'No kite moments shared yet',
            style: TextStyle(
              fontSize: 16.sp,
              color: KudoColors.black.withValues(alpha: 0.6),
              fontFamily: GoogleFonts.lato().fontFamily,
            ),
          ),
        ],
      ),
    );
  }

  /// 构建话题标签页内容 - 根据用户讨论记录筛选话题
  Widget _constructTopicsTabContent() {
    // 直接获取话题数据，避免触发状态更新
    final allTopics = KiteTopicController.globalInstance.getAllTopics();

    // 从默认讨论数据中筛选出该用户参与的话题
    final allDiscussions =
        KiteTopicDiscussionEntity.getDefaultTopicDiscussions();
    final userTopicIds =
        allDiscussions
            .where(
              (discussion) =>
                  discussion.publisherPersonaId ==
                  widget.targetUser.uniqueIdentifier,
            )
            .map((discussion) => discussion.topicIdentifier)
            .toSet()
            .toList();

    // 根据话题ID筛选出对应的话题
    final userTopics =
        allTopics
            .where((topic) => userTopicIds.contains(topic.uniqueIdentifier))
            .toList();

    if (userTopics.isEmpty) {
      return Center(
        child: Text(
          'No topic participation yet',
          style: TextStyle(
            fontSize: 16.sp,
            color: KudoColors.black.withValues(alpha: 0.6),
            fontFamily: GoogleFonts.lato().fontFamily,
          ),
        ),
      );
    }

    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        children:
            userTopics
                .map((topic) => _buildTopicParticipationItem(topic))
                .toList(),
      ),
    );
  }

  Widget _buildTopicParticipationItem(KiteTopicEntity topic) {
    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      child: AspectRatio(
        aspectRatio: 343 / 140,
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(12.r),
            image: DecorationImage(
              image: AssetImage(topic.topicImageResource),
              fit: BoxFit.cover,
            ),
          ),
        ),
      ),
    ).inkWell(
      onTap:
          () => AppNavigationManager.navigateToKiteTopicDetail(context, topic),
    );
  }

  /// 格式化日期 - 完全照抄IdentityScreen
  String _formatDate(DateTime date) {
    return '${date.month}.${date.day}';
  }

  /// 构建风筝时刻卡片 - 完全模仿IdentityScreen的卡片样式
  Widget _constructMomentCard(KiteMomentEntity moment) {
    return GestureDetector(
      onTap:
          () =>
              AppNavigationManager.navigateToKiteMomentDetail(context, moment),
      child: Container(
        margin: EdgeInsets.only(bottom: 10.h),
        child: AspectRatio(
          aspectRatio: 167 / 196,
          child: ClipRRect(
            borderRadius: BorderRadius.circular(10.r),
            child: Stack(
              children: [
                Positioned.fill(
                  child:
                      moment.mediaResourceUrl.isNotEmpty
                          ? ImageResourceHelper.buildImageWidget(
                            imagePath:
                                moment.isVideoType &&
                                        moment.thumbnailResourceUrl != null
                                    ? moment.thumbnailResourceUrl!
                                    : moment.mediaResourceUrl,
                            fit: BoxFit.cover,
                            errorWidget: Container(
                              decoration: BoxDecoration(
                                gradient: LinearGradient(
                                  colors: [
                                    Colors.purple.withValues(alpha: 0.8),
                                    Colors.pink.withValues(alpha: 0.8),
                                    Colors.orange.withValues(alpha: 0.8),
                                  ],
                                  begin: Alignment.topLeft,
                                  end: Alignment.bottomRight,
                                ),
                              ),
                            ),
                          )
                          : Container(
                            decoration: BoxDecoration(
                              gradient: LinearGradient(
                                colors: [
                                  Colors.purple.withValues(alpha: 0.8),
                                  Colors.pink.withValues(alpha: 0.8),
                                  Colors.orange.withValues(alpha: 0.8),
                                ],
                                begin: Alignment.topLeft,
                                end: Alignment.bottomRight,
                              ),
                            ),
                          ),
                ),
                // 顶部蒙层和举报按钮
                Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.all(12.w),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Colors.black.withValues(alpha: 0.6),
                          Colors.transparent,
                        ],
                      ),
                    ),
                    child: Row(
                      children: [
                        const Spacer(),
                        // 举报按钮
                        GestureDetector(
                          onTap: () => _showMomentReportDialog(moment),
                          child: SvgPicture.asset(
                            'assets/svg/report.svg',
                            width: 22.w,
                            height: 22.w,
                            colorFilter: ColorFilter.mode(
                              Colors.white,
                              BlendMode.srcIn,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                // 底部渐变蒙层和详情文字
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.all(12.w),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.bottomCenter,
                        end: Alignment.topCenter,
                        colors: [
                          Colors.black.withValues(alpha: 0.8),
                          Colors.transparent,
                        ],
                      ),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        // 第一排文字 - 标题
                        Text(
                          moment.momentTitle.isNotEmpty
                              ? moment.momentTitle
                              : 'Weekend Recharge Plan:',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 14.sp,
                            fontWeight: FontWeight.bold,
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                        SizedBox(height: 2.h),
                        // 第二排文字 - 内容
                        Text(
                          moment.contentText.isNotEmpty
                              ? moment.contentText
                              : 'Kite + Sunshine = Full...',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 12.sp,
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 显示风筝时刻举报弹窗
  void _showMomentReportDialog(KiteMomentEntity moment) {
    ReportDialog.show(
      context: context,
      title: 'Report Moment',
      onReport: (reportType) {
        // 举报成功后删除该风筝时刻并刷新列表
        _deleteMomentAndRefresh(moment);
        KudoToast.showSuccessToast(
          context,
          'Moment reported and removed successfully',
        );
      },
    );
  }

  /// 删除风筝时刻并刷新列表
  void _deleteMomentAndRefresh(KiteMomentEntity moment) {
    // 从控制器中删除该时刻
    KiteMomentController.globalInstance.deleteKiteMoment(
      moment.uniqueIdentifier,
    );

    // 刷新页面状态
    setState(() {
      // 重新加载用户数据
      _loadTargetUserData();
    });
  }
}

/// 虚线绘制器 - 用于绘制时间线的虚线连接（使用不同的类名）
class DashedLinePainter extends CustomPainter {
  final Color color;
  final double strokeWidth;
  final double dashWidth;
  final double dashSpace;

  DashedLinePainter({
    required this.color,
    this.strokeWidth = 2.0,
    this.dashWidth = 5.0,
    this.dashSpace = 3.0,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint =
        Paint()
          ..color = color
          ..strokeWidth = strokeWidth
          ..style = PaintingStyle.stroke;

    double startY = 0;
    while (startY < size.height) {
      canvas.drawLine(
        Offset(size.width / 2, startY),
        Offset(size.width / 2, startY + dashWidth),
        paint,
      );
      startY += dashWidth + dashSpace;
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}
